package project1.dao;

import project1.data.DataSet;
import project1.entity.Book;
import project1.entity.ShoppingCart;

public class ShoppingCartDaoImpl implements ShoppingCartDao {
    @Override
    public void insert(Book book, int count) {
        Integer all = DataSet.shoppingCart.get(book);
        if (all == null) {
            all = count;
        } else {
            all += count;
        }
        DataSet.shoppingCart.put(book, all);
    }

    @Override
    public void delete(Book book) {
        DataSet.shoppingCart.remove(book);
    }

    @Override
    public int queryCount(Book book) {
        Integer count = DataSet.shoppingCart.get(book);
        if (count == null) {
            count = 0;
        }
        return count;
    }

    @Override
    public ShoppingCart query() {
        return DataSet.shoppingCart;
    }
}
